package com.kuangstudy.thread.advanced;

import java.util.concurrent.*;

/**
 * @author Losca
 * @date 2021/7/22 16:10
 */
public class ThreadNew {
    public static void main(String[] args) {
        new MyThread1().start();
        MyThread2 myThread2 = new MyThread2();
        new Thread(myThread2).start();
        MyThread3 myThread3 = new MyThread3();
        Callable callable;
        FutureTask<Integer> futureTask = new FutureTask<>(myThread3);
        new Thread(futureTask).start();
        Integer integer = null;
        try {
            integer = futureTask.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        System.out.println(integer);

        System.out.println("=============");
        ExecutorService service = Executors.newFixedThreadPool(3);
        Future<Integer> submit = service.submit(myThread3);
        try {
            Integer integer1 = submit.get();
            System.out.println(integer1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        service.shutdown();
        /**
         * 继承Thread类
         * 实现Runable接口
         * 100
         * =============
         * 100
         */

    }
}

class MyThread1 extends Thread{
    @Override
    public void run() {
        System.out.println("继承Thread类");
    }
}

class MyThread2 implements Runnable{
    @Override
    public void run() {
        System.out.println("实现Runable接口");
    }
}

class MyThread3 implements Callable<Integer>{
    @Override
    public Integer call() throws Exception {
        System.out.println("callable实现");
        return 100;
    }
}